package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Permission;
import com._51cto.healthy.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permission")
public class permissionController {
    @DubboReference
    private PermissionService permissionService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R queryPageRole(@RequestParam(value = "query",required = false/*表示参数不是必填项*/) String query,
                           @PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize){
        P<Permission> permissionP = permissionService.queryPermissionAll(query, pageNum, pageSize);
        return R.success(permissionP,"查询成功");

    }
    @PostMapping
    public R insertPermission(@RequestBody Permission permission){
        permissionService.insert(permission);
        return R.success("新增成功");
    }
    @PutMapping
    public R updatePermission(@RequestBody Permission permission){
        permissionService.update(permission);
        return R.success("修改成功");
    }

    @DeleteMapping("/{id}")
    public R deletePermission(@PathVariable("id") Integer id){
        permissionService.deleteByPK(id);
        return R.success("删除成功");
    }
}
